import requests
import json
import random
import pymysql

host = "gz-cdb-7yh3glhn.sql.tencentcdb.com"
port = 62343
user = "cmountkuangyq"
pwd = "kuang2001031269"
dbname = "upin_coupon"

db = pymysql.connect(host, user, pwd, dbname, port)
cursor = db.cursor()
sql = "select openid from t_wechat_user  where  SUBSTR(openid,1,4)!='2088' and SUBSTR(openid,1,3)!='123' and " \
      "SUBSTR(openid,1,3)!='111' and mobile !='' limit 1000"  # 可修改数量，暂时限制1000
cursor.execute(sql)
openids = cursor.fetchall()
db.close()
print(openids)
# url = "http://yp-app.triumen.cn/user/wechat_register"
# openids = ['oMEuAwEZuaFOZrnI8-qAEyxMrk7U', 'oMEuAwMpAMqdioGDRH1Fj7Qe_jTg', 'oMEuAwJ8uyyHZzAr31ykRSpunKNQ',
#            'oMEuAwNpErk8AKaAOiVpmj4iwO8E', 'oMEuAwGZWcHktAbG2JUREjUtZTEE', 'oMEuAwM_ERQUlj7JjdtpXecSk3-c',
#            'oMEuAwCX5wa_4uUed93F2sO4It9U']
# headers = {"Content-Type": "application/text;charset=utf-8"}
# data = {"device_token": "", "vertype": "801", "plat": "android", "mobile_model": "android9", "version": "1.4.3",
#         "token": "", "nickname": "三观正", "avatar": "1", "type": 1,
#         'openid': random.choice(openids)}
# data = {"device_token": "", "vertype": "801", "plat": "android", "mobile_model": "android9", "version": "1.4.3",
#         "token": "", "nickname": "三观正", "avatar": "1", "type": 1,
#         'openid': ''}
# print(data['openid'])
# response = requests.post(url, headers=headers, data=json.dumps(data))
# result = response.json()
# try:
#     token = result['data']['token']
# except Exception:
#     pass
# else:
#     print(token)
